<layout-header></layout-header>

<nav class="container-xl mb-3">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a routerLink="/welcome">首页</a></li>
        <li class="breadcrumb-item active">Wcferry</li>
        <li class="breadcrumb-item active">聊天</li>
    </ol>
</nav>

<div class="container-xl mb-3">
    <div class="row g-3">
        <div class="col col-md-3">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <div class="input-group input-group-sm">
                        <input type="text" class="form-control" placeholder="搜索" [(ngModel)]="conactsFilter" />
                    </div>
                </div>
                <div class="list-group list-group-flush">
                    @for (item of contacts | filter:'wxid,name':conactsFilter;; track item.wxid) {
                    <a class="list-group-item list-group-item-action d-flex align-items-center cursor-pointer" [class.active]="chat.wxid == item.wxid" (click)="changeChat(item)">
                        <div class="avatar me-3">
                            <img class="rounded" [src]="avatars[item.wxid] || '/assets/icon.png'" />
                        </div>
                        <div class="text-truncate">
                            <div class="fw-bold text-truncate">{{item.remark || item.name || '-'}}</div>
                            <small>{{item.wxid}}</small>
                        </div>
                    </a>
                    }
                </div>
            </div>
        </div>
        <div class="col" [class.col-md-9]="!wechat.showPanel" [class.col-md-6]="wechat.showPanel">
            <layout-wechat #wechat [avatars]="avatars" [value]="chat"></layout-wechat>
        </div>
        <div class="col col-md-3" [class.d-none]="!wechat.showPanel">
            @if (chat.wxid && chat.wxid.includes('@chatroom')) {
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <div class="fs-5">
                        群成员
                    </div>
                </div>
                <div class="list-group list-group-flush">
                    @for (item of roomMembers[chat.wxid]; track item.wxid) {
                    <a class="list-group-item d-flex align-items-center">
                        <div class="avatar me-3">
                            <img class="rounded" [src]="avatars[item.wxid] || '/assets/icon.png'" />
                        </div>
                        <div class="text-truncate">
                            <div class="fw-bold text-truncate">{{item.remark || item.name || '-'}}</div>
                            <small>{{item.wxid}}</small>
                        </div>
                    </a>
                    }
                </div>
            </div>
            } @else {
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <div class="fs-5">
                        用户资料
                    </div>
                </div>
                <div class="list-group list-group-flush">
                    <div class="list-group-item">
                        {{chat.name}}
                    </div>
                    <div class="list-group-item">
                        {{chat.wxid}}
                    </div>
                </div>
            </div>
            }
        </div>
    </div>
</div>